//---------------------------------------------------------------------------

#ifndef MainSFH
#define MainSFH
#define MaxBusStop 10000;
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "UWebGMaps.hpp"
#include "UWebGMapsCommon.hpp"
#include <Data.DB.hpp>
#include <Data.Win.ADODB.hpp>
#include <System.Win.ScktComp.hpp>
#include <Vcl.ExtCtrls.hpp>
#include "AdvGroupBox.hpp"
#include "AdvOfficeButtons.hpp"
#include "AdvDateTimePicker.hpp"
#include <Vcl.ComCtrls.hpp>
#include "AdvMetroButton.hpp"
#include "AdvSmoothButton.hpp"
#include "AdvMenus.hpp"
#include <Vcl.Menus.hpp>
#include "AdvToolBar.hpp"
#include "AdvToolBarStylers.hpp"
#include "AdvShapeButton.hpp"
#include "AdvFontCombo.hpp"
#include "AdvSmoothDatePicker.hpp"
#include "AdvSmoothEdit.hpp"
#include "AdvSmoothEditButton.hpp"
#include <Vcl.Mask.hpp>
#include <Vcl.Imaging.pngimage.hpp>
#include "AeroLabel.hpp"
#include "datelbl.hpp"
#include "AdvOfficeStatusBar.hpp"
#include "AdvOfficeStatusBarStylers.hpp"
#include "AdvOfficeImage.hpp"
#include "AdvGrid.hpp"
#include "AdvObj.hpp"
#include "BaseGrid.hpp"
#include <Vcl.Grids.hpp>
#include "tmsAdvGridExcel.hpp"
#include <ComObj.hpp>
#include <utilcls.h>
//---------------------------------------------------------------------------
class TMain : public TAdvToolBarForm//TForm
{
__published:	// IDE-managed Components
	TWebGMaps *map;
	TADOConnection *gpsdb;
	TADOQuery *qAuto;
	TDataSource *dsAuto;
	TTimer *tmrUpdate;
	TADOQuery *qCombos;
	TDataSource *dsCombos;
	TAdvToolBarPager *tb1;
	TAdvPage *pgAdvToolBarPager12;
	TAdvPage *pgAdvToolBarPager13;
	TAdvToolBarOfficeStyler *advtlbrfcstylr1;
	TAdvPage *pg4;
	TAdvToolBar *advtlbr1;
	TAdvOfficeComboBox *eMarshrut;
	TAdvToolBar *advtlbr2;
	TAdvOfficeComboBox *eAuto;
	TAdvOfficeCheckBox *chkShowTrack;
	TComboBox *eAutoIMEI;
	TAdvToolBar *advtlbr3;
	TComboBox *eDiff;
	TAdvToolBarButton *btn2;
	TLabel *lblAuto;
	TAdvOfficeComboBox *eAutoOne;
	TAdvSmoothDatePicker *eDateFrom;
	TAdvSmoothDatePicker *eDateTo;
	TAdvOfficeStatusBar *sb;
	TAdvOfficeStatusBarOfficeStyler *advfcstsbrfcstylr1;
	TAdvPage *pg1;
	TAdvToolBar *advtlbr4;
	TAdvToolBar *advtlbr6;
	TAdvToolBar *advtlbr5;
	TAdvToolBar *advtlbr7;
	TAdvToolBarButton *btn3;
	TAdvToolBarButton *btn4;
	TAdvToolBarButton *btn5;
	TAdvToolBarButton *btn6;
	TAdvToolBar *advtlbr8;
	TAdvToolBarButton *btn7;
	TAdvShapeButton *btn1;
	TAdvOfficeImage *img4;
	TAdvOfficeImage *img1;
	TAdvOfficeImage *img2;
	TADOQuery *qStop;
	TDataSource *dsStop;
	TAdvToolBar *advtlbr9;
	TAdvToolBarButton *btnStop;
	TAdvToolBarButton *btnPause;
	TAdvToolBarButton *btnStart;
	TAdvToolBar *advtlbr10;
	TAdvOfficeCheckBox *chkShowStop;
	TAdvToolBarButton *btn8;
	TAdvToolBar *advtlbr11;
	TAdvOfficeCheckBox *chkDebug;
	TAdvSmoothDatePicker *eDebugDate;
	TAdvOfficeComboBox *eIcon;
	TAdvToolBar *advtlbr12;
	TAdvOfficeImage *img3;
	TAdvOfficeComboBox *eCarrier;
	TAdvStringGrid *sgAutos;
	TButton *btnAuto;
	TButton *btnRoute;
	TButton *btnCarrier;
	TEdit *eSearch;
	TButton *btnSearch;
	TAdvToolBar *advtlbr13;
	TAdvToolBarButton *btn9;
	TAdvToolBar *advtlbrRep;
	TAdvOfficeCheckBox *chkRun;
	TAdvSmoothDatePicker *dtpckRep1;
	TAdvOfficeComboBox *cbRouteRep;
	TLabel *lblRouteRep;
	TAdvToolBarButton *btnRep;
	TAdvGridExcelIO *advgrdxclRep;
	TAdvStringGrid *sgStopRep;
	TAdvToolBar *tbSaveRep;
	TAdvToolBarButton *btnSaveRep;
	TAdvToolBar *advtlbrRepAuto;
	TLabel *lblRepAuto;
	TAdvToolBarButton *btnRepAuto;
	TAdvOfficeCheckBox *advfchckbxRepAuto;
	TAdvSmoothDatePicker *dtpckRepAuto;
	TAdvOfficeComboBox *cbbRepAuto;
	TAdvToolBar *advtlbrRepC;
	TLabel *lblRepC;
	TAdvToolBarButton *btnRepC;
	TAdvOfficeCheckBox *advfchckbxRepC;
	TAdvSmoothDatePicker *dtpckRepC;
	TAdvOfficeComboBox *cbbRepC;
	TRadioGroup *rgRepAuto;
	TADOQuery *qReport;
	TDataSource *dsReport;
	TGroupBox *grpRep;
	TProgressBar *pbRep;
	TAdvToolBar *advtlbrSet;
	TAdvToolBarButton *btnSet;
	void __fastcall FormResize(TObject *Sender);
	void __fastcall FormShow(TObject *Sender);
	void __fastcall mapMapClick(TObject *Sender, double Latitude, double Longitude,
          int X, int Y, TMouseButton Button);
	void __fastcall mapDownloadFinish(TObject *Sender);
	void __fastcall tmrUpdateTimer(TObject *Sender);
	void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
	void __fastcall eMarshrutSelect(TObject *Sender);
	void __fastcall eAutoSelect(TObject *Sender);
	void __fastcall N2Click(TObject *Sender);
	void __fastcall btn2Click(TObject *Sender);
	void __fastcall btn5Click(TObject *Sender);
	void __fastcall mapMarkerDrag(TObject *Sender, UnicodeString MarkerTitle, int IdMarker,
          double Latitude, double Longitude);
	void __fastcall btnStartClick(TObject *Sender);
	void __fastcall btnPauseClick(TObject *Sender);
	void __fastcall btnStopClick(TObject *Sender);
	void __fastcall chkShowStopClick(TObject *Sender);
	void __fastcall mapMarkerClick(TObject *Sender, UnicodeString MarkerTitle, int IdMarker,
          double Latitude, double Longitude, TMouseButton Button);
	void __fastcall btn6Click(TObject *Sender);
	void __fastcall eIconChange(TObject *Sender);
	void __fastcall btn7Click(TObject *Sender);
	void __fastcall btn3Click(TObject *Sender);
	void __fastcall btn4Click(TObject *Sender);
	void __fastcall eCarrierChange(TObject *Sender);
	void __fastcall btnCarrierClick(TObject *Sender);
	void __fastcall btnRouteClick(TObject *Sender);
	void __fastcall btnAutoClick(TObject *Sender);
	void __fastcall btnSearchClick(TObject *Sender);
	void __fastcall sgAutosRowDisjunctSelected(TObject *Sender, int ARow);
	void __fastcall sgAutosGridHint(TObject *Sender, int ARow, int ACol, UnicodeString &hintstr);
	void __fastcall tb1Changing(TObject *Sender, int FromPage, int ToPage, bool &AllowChange);
	void __fastcall btn9Click(TObject *Sender);
	void __fastcall btnRepClick(TObject *Sender);
	void __fastcall btnSaveRepClick(TObject *Sender);
	String __fastcall ConvertUTCDate(TDate dDate, String sTime);
	void __fastcall btnRepAutoClick(TObject *Sender);
	void __fastcall cbRouteRepChange(TObject *Sender);
	void __fastcall cbbRepAutoChange(TObject *Sender);
	void __fastcall cbbRepCChange(TObject *Sender);
	void __fastcall btnRepCClick(TObject *Sender);
	void __fastcall btnSetClick(TObject *Sender);


private:	// User declarations
public:		// User declarations
	__fastcall TMain(TComponent* Owner);
	void __fastcall LoadAuto();
	void __fastcall GetAuto();
	void __fastcall GetStop();
	void __fastcall ShowStop(int iIconSize);
	void __fastcall HideStop();
	int __fastcall AddMarker(int iMarkerId,String Label,String sMarshrut,double Lat,double Long,UnicodeString Title,UnicodeString Icon,bool Draggable,bool Visible, bool Clickable,bool Flat,bool Animation,int zIndex);
 //	int __fastcall AddPolygon(double Lat,double Long);
	int iColAuto, iColBusStop, iSelectedAuto;
	void __fastcall UpdateMap(String sAutoIMEI);
	void __fastcall GetCurPosition(String sAutoIMEI);
	void __fastcall GetRoute(String sAutoIMEI);
	void __fastcall DelMarkerLink(bool bOnlyBusStop);
	String __fastcall ConvertDate(TDate dDate);
	String __fastcall ConvertTime(TTime tTime,bool bNow);
	double __fastcall ConvertCoordinates(String sCoord);
	String __fastcall ConvertCoord(String sCoord);
	void __fastcall FillCombo(TComboBox *Combo,String db_table,bool bSort,String sFieldName,bool bClearBefore,bool bGroup);
	void __fastcall FillCombo(TAdvOfficeComboBox *Combo,String db_table,bool bSort,String sFieldName,bool bClearBefore,bool bGroup);
	bool bAddingMarker,bNewPaint,bAddingRoute;
	void __fastcall ClearMap();
	int __fastcall FindStopId(int iMarker);
	String __fastcall FindStopName(int iMarker);
	int __fastcall FindStopMarker(int iId);
    String sDirPath;
};

class TAuto
{
	public:
	__fastcall TAuto();

	//void __fastcall ShowCurPosition(double Lat,double Long,UnicodeString Title,UnicodeString Icon,bool Draggable,bool Visible, bool Clickable,bool Flat,bool Animation,int zIndex);
	void __fastcall ShowCurPosition();
	String IMEI;
	String sIcon;
	String sNumber;
	int iSpeed,iDirect,iState,iId,iMarkerId;
	double lat,lng,newlat,newlng;
	String sRawLat,sRawLng,sLabel,sMarshrut;
	bool bShow;
};
//---------------------------------------------------------------------------

class TRoutePoint
{
	public:
	__fastcall TRoutePoint();
	//int *iPLat,*iPLng,*iPSpeed,*iPDirect,*iPState,*iPMarkerId;
	int *iPLat,*iPLng,*iPMarkerId;
	int iColCoord;
};

class TBusStop
{
	public:
	__fastcall TBusStop();
	int iMarkerId,iId;
	double dLat,dLng;
	String sName;
};

extern PACKAGE TMain *Main;
//---------------------------------------------------------------------------
#endif
